/* 
 * File:   test.c
 * Author: jonas
 *
 * Created on 3 décembre 2013, 20:58
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
 * 
 */

char buf[256];
char cType[1], cDimData[3], cData[252];
char cLogin[2], cNameLogin[50];
int iChoix, iType, iDimData;
int iLogin;

void main() {
    iChoix = 0;
    printf("****** Menu ******\n"
            "1 - Message\n"
            "2 - Fichier\n"
            "3 - Connexion\n"
            "Votre choix : ");
    scanf("%d", &iChoix);
    switch (iChoix) {
        case 1:
            break;
        case 2:
            break;
        case 3:
            // Formation de la trame
            iType = 3;

            printf("ID : ");
            scanf("%d", &iLogin);
            if (iLogin < 10) {
                sprintf(cLogin, "0%d", iLogin);
            } else {
                sprintf(cLogin, "%d", iLogin);
            }

            printf("Login : ");
            scanf("%s", &cNameLogin);
            /*
                        iDimData = strlen(cNameLogin);
                        if (iDimData < 10) {
                            sprintf(cDimData, "0%d", iDimData);
                        } else {
                            sprintf(cDimData, "%d", iDimData);
                        }
                        printf("Taille : %s\n", cDimData);
             */
            sprintf(buf, "%d%s", iType, cNameLogin);
            printf("Chaine : %s \n\n", buf);

            // Réinitialisation des variables
            iType = 0;
            iLogin = 0;
            iDimData = 0;
            sprintf(cNameLogin, "%s", "");

            // Décodage de la trame
            snprintf(cType, 2, "%s", buf);
            iType = atoi(cType);
            printf("Type : %d \n", iType);
/*
            snprintf(cLogin, 4, "%s", buf + 1);
            iLogin = atoi(cLogin);
            printf("ID : %d \n", iLogin);
*/
            /*
                        snprintf(cDimData, 5, "%s", buf + 4);
                        iDimData = atoi(cDimData);
                        printf("Taille : %d \n", iDimData);
             */
            sprintf(cNameLogin, "%s", buf + 1);
            printf("Login : %s \n", cNameLogin);
            break;
    }


}

/*
iDimData = strlen(cNameLogin);
            sprintf(cDimData, "%d", iDimData);
            if (iDimData < 10) {
                sprintf(cDimData, "00%d", iDimData);
            } 
            if (iDimData > 9 && iDimData < 100) {
                sprintf(cDimData, "0%d", iDimData);
            } 
 */
